<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 200px;
            height: 100px;
            background-color: pink;
            text-align: center;
            line-height: 100px;
            position: relative;
            margin: 100px auto;
        }

        span {
            display: block;
            width: 15px;
            height: 15px;
            line-height: 15px;
            position: absolute;
            border-radius: 50%;
            background-color: aqua;
            right: 0;
            top: 0;
            font-size: 8px;
            cursor: pointer;
        }
    </style>
</head>

<body>
    刘佳富 2024.7.27
    <div class="box">
        <h2>我是广告</h2>
        <span>X</span>
    </div>
    <div class="box">
        <h2>我是广告</h2>
        <span>X</span>
    </div>
    <div class="box">
        <h2>我是广告</h2>
        <span>X</span>
    </div>
    <div class="box">
        <h2>我是广告</h2>
        <span>X</span>
    </div>
    <script>
        // const span = document.querySelector('span')
        // span.addEventListener('click', function () {
        //     span.parentNode.style.display = "none"
        // })
        const span = document.querySelectorAll('span')
        // for (let i = 0; i < span.length; i++) {
        //     span[i].addEventListener('click', function () {
        //         this.parentNode.style.display = 'none'
        //     })
        // }
        // 5秒之后关闭广告
        setTimeout(function () {
            for (let i = 0; i < span.length; i++) {
                span[i].parentNode.style.display = ' none'
            }

        }, 5000)




    </script>
</body>

</html>